import datetime
import pytz
from peewee import PostgresqlDatabase
from peewee import CharField, TextField, DateTimeField, IntegerField, Model, ForeignKeyField


db = PostgresqlDatabase(
    'django',  # Required by Peewee.
    user='makemoney',  # Will be passed directly to psycopg2.
    password='makemoney_123.',  # Ditto.
    host='10.0.1.107',  # Ditto.
)

db_novel = PostgresqlDatabase(
    'novel',  # Required by Peewee.
    user='makemoney',  # Will be passed directly to psycopg2.
    password='makemoney_123.',  # Ditto.
    host='10.0.1.107',  # Ditto.
)


class Post(Model):
    title = CharField(max_length=2000)
    text = TextField()
    add_time = DateTimeField(default=datetime.datetime.now)
    author_id = IntegerField(null=True)
    bury = IntegerField(default=0)
    dig = IntegerField(default=0)
    site_name = CharField(max_length=300)
    site_id = IntegerField(null=True)

    class Meta:
        database = db
        db_table = 'posts_post'

class Author(Model):
    name = CharField(max_length=2000)
    class Meta:
        database = db_novel

class Category(Model):
    name = CharField(max_length=2000)
    class Meta:
        database = db_novel

class Novel(Model):
    rank = IntegerField()
    title = CharField(max_length=2000)
    category = ForeignKeyField(Category, related_name='category')
    author = ForeignKeyField(Author, related_name='author')
    class Meta:
        database = db_novel

class Article(Model):
    novel = ForeignKeyField(Novel, related_name='novel')
    chapter_id = IntegerField()
    text = TextField()
    title = CharField(max_length=2000)
    class Meta:
        database = db_novel
